package com.sgb.kjwl.view.ui.adapter.manage;

import android.content.Context;
import android.view.View;

import androidx.core.util.Pair;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemIprBinding;
import com.sgb.kjwl.model.entity.manage.IPDetailEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.view.ui.activity.manage.ShopInfoForCompanyTradesActivity;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

import static com.sgb.kjwl.view.ui.activity.manage.IPActivity.KEY_BRAND;
import static com.sgb.kjwl.view.ui.activity.manage.IPActivity.KEY_PATENT;

public class IPAdapter extends BaseRecycleAdapter<IPDetailEntity> {
    private Context context;

    public IPAdapter(Context context, List<IPDetailEntity> datas) {
        super(context, R.layout.item_ipr, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, IPDetailEntity ipDetailEntity) {
        holder.setBinding(BR.viewModel, ipDetailEntity);
        ItemIprBinding itemIprBinding = (ItemIprBinding) holder.getmBinding();
        RequestOptions options;
        if (KEY_BRAND.equals(ipDetailEntity.getTypesOfPropertyRights())) {
            options = new RequestOptions().placeholder(R.mipmap.morentu1_0_3)//图片加载出来前，显示的图片
                    .error(R.mipmap.morentu1_0_3);//图片加载失败后，显示的图片
        } else if (KEY_PATENT.equals(ipDetailEntity.getTypesOfPropertyRights())) {
            options = new RequestOptions().placeholder(R.mipmap.morentu1_0_3)//图片加载出来前，显示的图片
                    .error(R.mipmap.morentu1_0_3);//图片加载失败后，显示的图片
        } else {
            options = new RequestOptions().placeholder(R.mipmap.morentu1_0_3)//图片加载出来前，显示的图片
                    .error(R.mipmap.morentu1_0_3);//图片加载失败后，显示的图片
        }
        Glide.with(context).load(ipDetailEntity.getUploadPictures()).apply(options)//异常时候显示的图片
                .into((itemIprBinding.logoView));
        itemIprBinding.titleView.setText(ipDetailEntity.getName());
        itemIprBinding.patentType.setText(ipDetailEntity.getType());
        itemIprBinding.fieldCategory.setText(ipDetailEntity.getFieldClassName());
        itemIprBinding.companyName.setText(ipDetailEntity.getCompanyName());
        if (ipDetailEntity.getState().isEmpty()) {
            itemIprBinding.patentState.setText("");
        } else if (ipDetailEntity.getState().equals("2")) {
            itemIprBinding.patentState.setText("授权已下证");
        } else if (ipDetailEntity.getState().equals("1")) {
            itemIprBinding.patentState.setText("授权未下证");
        }
        itemIprBinding.btnEnterEnterprise.setOnClickListener(view -> WebsiteInfoActivity.start(context,ipDetailEntity.getCompanyNo(),1));
        switch (ipDetailEntity.getTypesOfPropertyRights()) {
            case "商标":
            case "版权":
                itemIprBinding.llField.setVisibility(View.GONE);
                itemIprBinding.llState.setVisibility(View.GONE);
                break;
            case "专利":
                itemIprBinding.llField.setVisibility(View.VISIBLE);
                itemIprBinding.llState.setVisibility(View.VISIBLE);
                break;
        }
    }
}
